package com.meeting.meetingroom_api.entity;

import com.meeting.meetingroom_api.enums.AccountStatus;
import com.meeting.meetingroom_api.enums.CustomerApprovalStatus;
import com.meeting.meetingroom_api.enums.UserRole;
import jakarta.persistence.*;
import jakarta.persistence.Convert; // 确保导入 @Convert
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

@Entity
@Table(name = "users")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id")
    private Integer userId;

    @Column(name = "username", nullable = false, unique = true)
    private String username;

    @Column(name = "full_name", nullable = false)
    private String fullName;

    @Column(name = "password_hash", nullable = false)
    private String passwordHash; // 存储加密后的密码

    @Enumerated(EnumType.STRING)
    @Column(name = "role", nullable = false)
    private UserRole role;

    @Column(name = "company_name")
    private String companyName;

    @Column(name = "phone_number")
    private String phoneNumber;

    @Enumerated(EnumType.STRING)
    @Column(name = "customer_approval_status")
    private CustomerApprovalStatus customerApprovalStatus;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "approved_by_admin_id")
    private User approvedByAdmin; // 审批该客户注册的管理员

    @Column(name = "approved_at")
    private LocalDateTime approvedAt;

     @Enumerated(EnumType.STRING)
    @Column(name = "account_status")
    private AccountStatus accountStatus;

    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    @UpdateTimestamp
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    // Relationships (if any, e.g., bookings made by this user)
    // @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
    // private List<Booking> bookings;

    // @OneToMany(mappedBy = "approvedByAdmin", cascade = CascadeType.ALL)
    // private List<User> approvedCustomers; // If an admin can approve multiple customers
}